/* GUI CONVERTED from reject.p (converter v1.76) Sun Aug 25 20:59:35 2002 */
/* reject.p - REPETITIVE REJECT TRANSACTION                                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.7.3.6 $                                                               */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 03/09/95   BY: WUG *G0GR*                */
/* REVISION: 7.3      LAST MODIFIED: 03/29/95   BY: dzn *F0PN*                */
/* REVISION: 7.3      LAST MODIFIED: 02/21/96   BY: jym *G1M9*                */
/* REVISION: 7.3      LAST MODIFIED: 03/19/96   BY: jym *G1PZ*                */
/* REVISION: 7.3      LAST MODIFIED: 05/16/96   BY: *G1VW* Julie Milligan     */
/* REVISION: 8.6      LAST MOSIFIED: 06/11/96   BY: *K001* Alma Lara          */
/* REVISION: 7.3      LAST MODIFIED: 07/02/96   BY: *G1Z7* Julie Milligan     */
/* REVISION: 8.7      LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.7      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 09/28/98   BY: *J310* Santhosh Nair      */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* Revision: 1.7.3.4  BY: Hualin Zhong          DATE: 05/30/01 ECO: *N0YY*    */
/* Revision: 1.7.3.5  BY: Robin McCarthy        DATE: 10/01/01 ECO: *P025*    */
/* $Revision: 1.7.3.6 $       BY: Vivek Gogte           DATE: 08/06/02 ECO: *N1QQ*    */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*V8:ConvertMode=Maintenance                                                  */

{mfdtitle.i "2+ "}
{gldydef.i new}
{gldynrm.i new}
{retrform.i new}

define buffer next_wr_route for wr_route.
define buffer ptmstr for pt_mstr.
define new shared variable rsn_codes as character extent 10.
define new shared variable quantities like wr_qty_comp extent 10.
define new shared variable reject_rsn_codes as character extent 10.
define new shared variable reject_quantities like wr_qty_comp
   extent 10.
define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
define variable batchqty as decimal.
define variable comp as character.
define variable conv_qty_rjct as decimal.
define variable conv_qty_scrap as decimal.
define variable cumwo_lot as character.
define variable ophist_recid as recid.
define variable rejected like mfc_logical.
define variable schedwo_lot as character.
define variable trans_type as character.
define variable undo_stat like mfc_logical no-undo.
define variable undostat like mfc_logical no-undo.
define variable yn like mfc_logical.
define variable i as integer.
define variable j as integer.
define variable total_reject_qty as decimal.
define variable first_op like mfc_logical.
define variable msg_ct as integer.
define variable new_conv like conv.
define variable input_que as log initial yes.
define variable output_que as log initial no.
define variable prev_op as integer.
define variable fromqueue as character no-undo.
{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/
define variable move_to_wkctr like wc_wkctr no-undo.
define variable move_to_mch like wc_mch no-undo.

if is_wiplottrace_enabled() then
   run activate_wip_lot_trace.

/* DO NOT RUN PROGRAM UNLESS QAD_WKFL RECORDS HAVE */
/* BEEN CONVERTED SO THAT QAD_KEY2 HAS NEW FORMAT  */
if can-find(first qad_wkfl where qad_key1 = "rpm_mstr") then do:
   /* UTILITY: utrecov2.p MUST BE RUN PRIOR TO EXECUTING THIS PROGRAM */
   {pxmsg.i &MSGNUM=5126 &ERRORLEVEL=3}
   message.
   message.
   leave.
end.

eff_date = today.
find first gl_ctrl no-lock.

{gprun.i ""redflt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   /*GET EMP, EFFDATE, SHIFT, SITE, CONTROLTOTAL FROM USER*/
   {gprun.i ""retrin1.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if undo_stat then undo, leave.
   wo-loop:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

      /*GET ITEM, OP, LINE FROM USER*/
      {gprun.i ""retrin2.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if undo_stat then undo, leave.

      /*FIND REPETITIVE SCHEDULE TO UPDATE*/
      {gprun.i ""reoptr1b.p"" "(input  site,
                                input  line,
                                input  part,
                                input  op,
                                input  eff_date,
                                output routing,
                                output bom_code,
                                output schedwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if schedwo_lot = "?" then do:
         /* Unexploded schedule with consumption period */
         {pxmsg.i &MSGNUM=325 &ERRORLEVEL=3}
         next-prompt part.
         undo, retry.
      end.

      /*GET BOM, ROUTING FROM USER*/
      {gprun.i ""retrin3.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if undo_stat then undo, leave.

      /*FIND CUM ORDER.  */
      {gprun.i ""regetwo.p"" "(input site,
                               input part,
                               input eff_date,
                               input line,
                               input routing,
                               input bom_code,
                               output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /*VALIDATE THE OPERATION */
      {reopval.i &part = part
                 &routing = routing
                 &op = op
                 &date = eff_date
                 &prompt = op
                 &frame = "a"
                 &leave = ""no""
                 &loop = "mainloop"}

      /* CREATE IT IF IT DOESN'T EXIST*/
      if cumwo_lot = ? then do:
         {gprun.i ""recrtwo.p"" "(input  site,
                                  input  part,
                                  input  eff_date,
                                  input  line,
                                  input  routing,
                                  input  bom_code,
                                  output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if cumwo_lot = ? then next wo-loop.
         display cumwo_lot @ wo_lot with frame a.
      end.
      else do:
         display cumwo_lot @ wo_lot with frame a.
         find wo_mstr where wo_lot = cumwo_lot no-lock.

         if wo_status = "c" then do:
            /* CUM ORDER IS CLOSED */
            {pxmsg.i &MSGNUM=5101 &ERRORLEVEL=3}
            undo, retry.
         end.
      end.

      find wr_route where wr_lot = cumwo_lot and wr_op = op no-lock
         no-error.
      if not available wr_route then do:
         /* OPERATION DOES NOT EXIST */
         {pxmsg.i &MSGNUM=106 &ERRORLEVEL=3}
         next-prompt op with frame a.
         undo, retry.
      end.

      if not wr_milestone then do:
         /* OPERATION NOT A MILESTONE */
         {pxmsg.i &MSGNUM=560 &ERRORLEVEL=2}

         if is_wiplottrace_enabled() then do:
            run check_non_milestone (input  cumwo_lot,
                                     input  op,
                                     output undo_stat).
            if undo_stat then undo, retry.
         end.
      end.

      find last wr_route where wr_lot = cumwo_lot and wr_op < op
         no-lock no-error.
      first_op = not available wr_route.

      if available wr_route then prev_op = wr_op.
      else prev_op = ?.

      find wr_route where wr_lot = cumwo_lot and wr_op = op no-lock.

      display wr_desc with frame a.

      assign
         wkctr = ""
         mch = ""
         dept = ""
         um = ""
         conv = 1
         from_que = output_que
         qty_rjct = 0
         rjct_rsn_code = ""
         rejque_multi_entry = no
         to_op = wr_op
         rsn_codes = ""
         quantities = 0
         reject_rsn_codes = ""
         reject_quantities = 0.

      {gprun.i ""resetmno.p"" "(input  cumwo_lot,
                                input  op,
                                output move_next_op)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      wkctr = wr_wkctr.
      mch = wr_mch.
      find wc_mstr where wc_wkctr = wkctr and wc_mch = mch no-lock.

      dept = wc_dept.
      find dpt_mstr where dpt_dept = wc_dept no-lock no-error.

      find wo_mstr where wo_lot = cumwo_lot no-lock.
      find pt_mstr where pt_part = wo_part no-lock.
      um = pt_um.

      find first ea_mstr where ea_type = "1" no-lock no-error.
      if available ea_mstr then earn_code = ea_earn.

      display
         wkctr
         mch
         wc_desc
         dept
         dpt_desc when (available dpt_mstr)
         ""       when (not available dpt_mstr) @ dpt_desc
         um
         conv
         from_que
         qty_rjct
         rjct_rsn_code
         rejque_multi_entry
         to_op
         "" @ wr_desc
      with frame reject1.

      if is_wiplottrace_enabled() then
         run init_reject_input_wip_lot_temptable
            in h_wiplottrace_procs.

      do with frame reject1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         do with frame reject1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

            {regetwcm.i &framename=reject1}

            do with frame reject1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

               set
                  dept
                  um
                  conv
                  from_que when (not first_op)
                  qty_rjct
                  rjct_rsn_code
                     when (not (is_wiplottrace_enabled() and
                                is_operation_queue_lot_controlled(cumwo_lot,
                                   op, if input from_que = input_que then
                                   INPUT_QUEUE else OUTPUT_QUEUE)))
                  rejque_multi_entry
                     when (not (is_wiplottrace_enabled() and
                           is_operation_queue_lot_controlled(cumwo_lot,
                              op, if input from_que = input_que then
                              INPUT_QUEUE else OUTPUT_QUEUE)))

                  editing:
                  global_lot = cumwo_lot.

                  {gpbrparm.i &browse=gplu223.p &parm=c-brparm1
                              &val=getTermLabel(""REJECT"",8)}
                  {gpbrparm.i &browse=gpbr223.p &parm=c-brparm1
                              &val=getTermLabel(""REJECT"",8)}

                  if frame-field = "dept" then do:
                     {mfnp05.i dpt_mstr dpt_dept yes dpt_dept
                        "input frame reject1 dept"}

                     if recno <> ? then
                     display
                        dpt_dept @ dept
                        dpt_desc.
                  end.
                  else
                     if frame-field = "rjct_rsn_code" then do:
                     {mfnp05.i rsn_ref rsn_type "rsn_type = ""reject"""
                        rsn_code "input frame reject1 rjct_rsn_code"}

                     if recno <> ? then
                        display rsn_code @ rjct_rsn_code.
                  end.

                  else do:
                     ststatus = stline[3].
                     status input ststatus.
                     readkey.
                     apply lastkey.
                  end.
               end.

               find dpt_mstr where dpt_dept = dept no-lock no-error.

               if not available dpt_mstr then do:
                  next-prompt dept.
                  /* DEPARTMENT DOES NOT EXIST */
                  {pxmsg.i &MSGNUM=532 &ERRORLEVEL=3}
                  undo, retry.
               end.

               display dpt_desc.

               find pt_mstr where pt_part = part no-lock.

               if um <> pt_um then do:
                  {gprun.i ""gpumcnv.p"" "(input  um,
                                           input  pt_um,
                                           input  part,
                                           output new_conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if new_conv = ? then do:
                     /* NO UNIT OF MEASURE CONVERSION EXISTS */
                     {pxmsg.i &MSGNUM=33 &ERRORLEVEL=2}
                  end.
                  else do:
                     if not frame reject1 conv entered then do:
                        conv = new_conv.
                        display conv.
                     end.
                  end.
               end.

               find rsn_ref where rsn_code = rjct_rsn_code
                  and rsn_type = "reject" no-lock no-error.

               if not available rsn_ref and rjct_rsn_code > "" then do:
                  /* REASON CODE DOES NOT EXIST */
                  {pxmsg.i &MSGNUM=534 &ERRORLEVEL=2}
               end.

               if not first_op then do:

                  if from_que = input_que then do:
                     find last wr_route
                        where wr_lot = cumwo_lot and wr_op < op
                        no-lock.
                     to_op = wr_op.
                  end.
                  else
                     to_op = op.

                  display to_op with frame reject1.

                  run get_to_op.
                  if undo_stat then undo, retry.

               end.

               if rejque_multi_entry then do:
                  do i = 1 to 10:
                     assign
                        rsn_codes[i]  = reject_rsn_codes[i]
                        quantities[i] = reject_quantities[i].
                  end.

                  {gprun.i ""resrqrin.p"" "(input ""reject"",
                                            input  getFrameTitle(""REJECT"",8),
                                            output undostat)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if undostat then undo, retry.
                  qty_rjct = 0.

                  do i = 1 to 10:
                     assign
                        reject_rsn_codes[i]  = rsn_codes[i]
                        reject_quantities[i] = quantities[i]
                        qty_rjct             = qty_rjct + quantities[i].
                  end.

                  display qty_rjct with frame reject1.
               end.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         conv_qty_rjct = qty_rjct * conv.

         /*CHECK QUEUES IF WOULD GO NEGATIVE; IF SO ISSUE MESSAGES*/

         run check_queues.

         /* GET DESTINATION WORKCENTER AND MACHINE,
          * REJECT INPUT WIP LOTS FROM USER       */

         run get_wiplottrace_input.
         if undo_stat then undo, retry.

         yn = yes.
         /* PLEASE CONFIRM UPDATE */
         {pxmsg.i &MSGNUM=32 &ERRORLEVEL=1 &CONFIRM=yn}
         if yn <> yes then undo, retry.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /****************************************************************/
      /*GOT ALL DATA AND VALIDATED IT, NOW WE CAN DO SOMETHING WITH IT*/
      /****************************************************************/

      /*NO TRANSACTION SHOULD BE PENDING HERE*/
      {gprun.i ""gpistran.p"" "(input 1, input """")"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if is_wiplottrace_enabled()
         and is_operation_queue_lot_controlled(cumwo_lot, op, fromqueue)
      then do:
         run process_rejects (input cumwo_lot,
                              input op,
                              input emp,
                              input site,
                              input wkctr,
                              input mch,
                              input dept,
                              input shift,
                              input eff_date,
                              input from_que,
                              input to_op,
                              input conv,
                              input move_to_wkctr,
                              input move_to_mch).
      end.
      else do:

         /*MOVE TO OUTQUE OF TARGET OPERATION*/
         assign
            conv_qty_rjct = qty_rjct * conv
            global_addr = ?
            trans_type = "REJECT".

         if from_que = input_que then do:

            /*MOVE BACK TO PREV OP OUTPUT QUE*/
            {gprun.i ""reophist.p"" "(input trans_type,
                                      input cumwo_lot,
                                      input prev_op,
                                      input emp,
                                      input wkctr,
                                      input mch,
                                      input dept,
                                      input shift,
                                      input eff_date,
                                      output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            /*MOVE BACK THRU TO DESTINATION OP OUTPUT QUE IF NECESSARY*/
            {gprun.i ""removea.p"" "(input cumwo_lot,
                                     input prev_op,
                                     input eff_date,
                                     input ophist_recid,
                                     input (- conv_qty_rjct))"}
/*GUI*/ if global-beam-me-up then undo, leave.


            {gprun.i ""rejectb.p"" "(input cumwo_lot,
                                     input prev_op,
                                     input to_op,
                                     input emp,
                                     input shift,
                                     input eff_date,
                                     input conv_qty_rjct,
                                     input trans_type)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         end.
         else do:
            {gprun.i ""rejectb.p"" "(input cumwo_lot,
                                     input op,
                                     input to_op,
                                     input emp,
                                     input shift,
                                     input eff_date,
                                     input conv_qty_rjct,
                                     input trans_type)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         /*PROCESS REJECT QUANTITY*/
         if rejque_multi_entry then do:
            do i = 1 to 10:
               if reject_quantities[i] <> 0 then do:
                  trans_type = "REJECT".
                  conv_qty_rjct = reject_quantities[i] * conv.

                  {gprun.i ""reophist.p"" "(input trans_type,
                                           input cumwo_lot,
                                           input to_op,
                                           input emp,
                                           input wkctr,
                                           input mch,
                                           input dept,
                                           input shift,
                                           input eff_date,
                                           output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  {gprun.i ""rejecta.p"" "(input cumwo_lot,
                                           input to_op,
                                           input op,
                                           input reject_rsn_codes[i],
                                           input ophist_recid,
                                           input conv_qty_rjct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               end.
            end.
         end.
         else do:
            trans_type = "REJECT".
            conv_qty_rjct = qty_rjct * conv.

            {gprun.i ""reophist.p"" "(input  trans_type,
                                      input  cumwo_lot,
                                      input to_op,
                                      input emp,
                                      input  wkctr,
                                      input mch,
                                      input dept,
                                      input shift,
                                      input  eff_date,
                                      output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            {gprun.i ""rejecta.p"" "(input cumwo_lot,
                                     input to_op,
                                     input op,
                                     input rjct_rsn_code,
                                     input ophist_recid,
                                     input conv_qty_rjct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
      end.

      if global_addr = ? then global_addr = string(ophist_recid).
      {gprun.i ""reintchk.p"" "(input cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.

end.
/*GUI*/ if global-beam-me-up then undo, leave.


if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.

PROCEDURE process_rejects:
   define input parameter cumwo_lot as character no-undo.
   define input parameter op like wr_op no-undo.
   define input parameter emp like op_emp no-undo.
   define input parameter site like op_site no-undo.
   define input parameter wkctr like wr_wkctr no-undo.
   define input parameter mch like wr_mch no-undo.
   define input parameter dept as character no-undo.
   define input parameter shift like op_shift no-undo.
   define input parameter eff_date as date no-undo.
   define input parameter from_que like mfc_logical no-undo.
   define input parameter to_op like wr_op no-undo.
   define input parameter conv like um_conv no-undo.
   define input parameter move_to_wkctr like wr_wkctr no-undo.
   define input parameter move_to_mch like wr_mch no-undo.

   run reject_reject_wip_lots in h_wiplottrace_procs
      (cumwo_lot, op, emp, site, wkctr, mch, dept, shift, eff_date,
       if from_que = input_que then INPUT_QUEUE else OUTPUT_QUEUE,
       to_op, conv, move_to_wkctr, move_to_mch).
END PROCEDURE.

/* WARN USER WHEN OP IS NON-MILESTONE */
PROCEDURE check_non_milestone:
   define input parameter cumwo_lot like wo_lot no-undo.
   define input parameter op like wr_op no-undo.
   define output parameter undo_stat like mfc_logical no-undo.

   undo_stat = no.

   if prev_milestone_operation(cumwo_lot, op) <> ?
      and is_operation_queue_lot_controlled
      (cumwo_lot,
      prev_milestone_operation(cumwo_lot, op),
      OUTPUT_QUEUE)
   then do:
      {pxmsg.i &MSGNUM=8465 &ERRORLEVEL=3}
      /* WIP LOT TRACE IS ENABLED AND OPERATION IS A NON-MILESTONE */
      undo_stat = yes.
   end.
END PROCEDURE.

/* ACTIVATE WIP LOT TRACE PROCEDURES */
PROCEDURE activate_wip_lot_trace:

   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}

END PROCEDURE.

PROCEDURE check_queues:
   msg_ct = 0.

   if from_que = input_que then do:
      /*CHECK INPUT QUEUE*/
      {gprun.i ""rechkq.p"" "(input cumwo_lot,
                              input op,
                              input ""i"",
                              input (- conv_qty_rjct),
                              input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
   else do:
      /*CHECK OUTPUT QUEUE*/
      {gprun.i ""rechkq.p"" "(input cumwo_lot,
                              input op,
                              input ""o"",
                              input (- conv_qty_rjct),
                              input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

   /*CHECK REJECT QUEUE*/
   {gprun.i ""rechkq.p"" "(input cumwo_lot, input to_op,
                           input ""r"",
                           input conv_qty_rjct,
                           input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /*FORCE A PAUSE IF NECESSARY*/
   {gprun.i ""repause.p"" "(input msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

END PROCEDURE.

PROCEDURE get_wiplottrace_input:
   if is_wiplottrace_enabled()
      and is_operation_queue_lot_controlled(cumwo_lot, op, fromqueue)
   then do:
      run get_destination_wkctr_mch_from_user
         in h_wiplottrace_procs (input  cumwo_lot,
                                 input  to_op,
                                 output move_to_wkctr,
                                 output move_to_mch,
                                 output undo_stat).

      if undo_stat then leave.

      run get_reject_input_wip_lots_from_user
         in h_wiplottrace_procs (input  cumwo_lot,
                                 input  op,
                                 input  qty_rjct,
                                 if from_que = input_que then INPUT_QUEUE
                                 else OUTPUT_QUEUE,
                                 input  conv,
                                 input  um,
                                 input  to_op,
                                 input  site,
                                 input  wkctr,
                                 input  mch,
                                 input  move_to_wkctr,
                                 input  move_to_mch,
                                 output undo_stat).

      if undo_stat then leave.
   end.
END PROCEDURE.

PROCEDURE get_to_op:
   undo_stat = true.

   do with frame reject1 on error undo, retry
         on endkey undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.


      set to_op with frame reject1
      editing:
         {mfnp05.i wr_route wr_lot
            "wr_lot = cumwo_lot and wr_op <= op"
            wr_op "input frame reject1 to_op"}

         if recno <> ? then do:
            display wr_op @ to_op wr_desc.
         end.
      end.

      find wr_route where wr_lot = cumwo_lot and
         wr_op = to_op
         no-lock no-error.

      if not available wr_route then do:
         /* OPERATION DOES NOT EXIST */
         {pxmsg.i &MSGNUM=106 &ERRORLEVEL=3}
         next-prompt to_op.
         undo, retry.
      end.

      if to_op > op then do:
         /* TO OPERATION FOLLOWS THIS OPERATION */
         {pxmsg.i &MSGNUM=5110 &ERRORLEVEL=3}
         next-prompt to_op.
         undo, retry.
      end.

      if from_que = input_que and to_op = op then do:
         /* INPUT QUEUE QUANTITIES MUST BE REJECTED TO A PRIOR OPERATION */
         {pxmsg.i &MSGNUM=272 &ERRORLEVEL=3}
         next-prompt to_op.
         undo, retry.
      end.

      if from_que = input_que then
         fromqueue = INPUT_QUEUE.
      else
         fromqueue = OUTPUT_QUEUE.

      if is_wiplottrace_enabled()
         and is_operation_queue_lot_controlled(cumwo_lot, op, fromqueue)
      then do:
         if not is_operation_queue_lot_controlled(cumwo_lot,
            to_op, REJECT_QUEUE)
         then do:
            {pxmsg.i &MSGNUM=8426 &ERRORLEVEL=3}
            /*TO OP MUST BE LOT CONTROLLED*/
            undo, retry.
         end.
      end.

      display wr_desc.

      undo_stat = false.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.

END PROCEDURE.
